package com.breeze.components.log.provider.json;

import ch.qos.logback.classic.spi.ILoggingEvent;
import com.fasterxml.jackson.core.JsonGenerator;
import java.io.IOException;
import net.logstash.logback.composite.AbstractFieldJsonProvider;
import net.logstash.logback.composite.FieldNamesAware;
import net.logstash.logback.composite.JsonWritingUtils;
import net.logstash.logback.fieldnames.LogstashFieldNames;

/**
 * @author breeze
 */
public abstract class BaseJsonProvider extends AbstractFieldJsonProvider<ILoggingEvent>
    implements FieldNamesAware<LogstashFieldNames> {

  public BaseJsonProvider() {}

  @Override
  public void writeTo(JsonGenerator generator, ILoggingEvent event) throws IOException {
    String value = this.getValue(event);
    JsonWritingUtils.writeStringField(generator, this.getFieldName(), value);
  }

  protected abstract String getValue(ILoggingEvent event);
}
